package com.hayato.demo.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import org.apache.commons.lang.StringUtils;

import com.hayato.demo.utils.Constant;

@SuppressWarnings( "serial" )
public class ErrorServlet extends HttpServlet {
	
	String page = Constant.DISP_ERROR; 
	
	private final String PARAM_ACTION = "action";
	
	public void doGet( HttpServletRequest request, HttpServletResponse response )
			throws IOException, ServletException {
		
		String action = request.getParameter( PARAM_ACTION );
		String previousPage = request.getParameter( "previousPage" );

		if( !StringUtils.isEmpty( action) ) {
			if( previousPage.equals( Constant.DISP_READ_CUSTOMER ) ) {
				page = Constant.DISP_READ_CUSTOMER;
			} else if( previousPage.equals( Constant.DISP_READ_PRODUCT )) {
				page = Constant.DISP_READ_PRODUCT;
			} else if( previousPage.equals( Constant.DISP_SEARCH_CUSTOMER ) ) {
				page = Constant.DISP_SEARCH_CUSTOMER;
			}
		}
		response.sendRedirect( page );
	}

	public void doPost( HttpServletRequest request, HttpServletResponse response )
			throws IOException, ServletException {
		doGet( request, response );
	}
}
